<?php
declare (strict_types=1);

namespace app\index\controller;

use addons\V2\admin\model\ProductCate;
use app\common\model\Carousel;
use app\common\model\TaskList;
use app\common\controller\Config;
use think\facade\Cache;
use app\common\tool\Result;
use think\exception\ValidateException;
use think\facade\View;

class Index extends Base
{

    public function index()
    {
        View::assign([
            'carousel' => Carousel::getList(),
            'cate'     => ProductCate::where(['status' => 1,'pid' => 0])->select()
        ]);
        return View::fetch();
    }

    public function communal()
    {
        $type = $this->request->param('type');
        $title = [ 'privacy_msg' => '注册协议'];

        View::assign([
            'title'   => $title[$type],
            'content' => Cache::get('system')[$type]
        ]);
        return View::fetch();
    }
    /**
     * 任务记录
     */
    public function taskAdd(){
        
        try {
            $param = $this->request->post();
            $sysm= Config::lists();
            $taskcount =TaskList::where('uid',$this->user->id)->whereDay('create_time')->count();
            if($taskcount>=$sysm['free_num']){
                return Result::fail('任务已完成');
            }
            return Result::fastReturn(TaskList::taskAdd($param,$this->user,$sysm));
        } catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }
    }
}
